package com.example.demo.demo;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author <a href="mailto:zhouyong@cqyyt.com">user</a>
 * @version 1.0
 * @date 2020/7/7 22:48
 */
public class demo3 {


    public static void main(String[] args) {
        List<person> list = Arrays.asList(
                new person("1","zy","16"),
                new person("2","zy1","12"),
                new person("3","zy2","14")
        );

        //对数据进行过滤，collect收集
        List<person> collect = list.stream().filter(p -> Integer.parseInt(p.getAge())>15).collect(Collectors.toList());

        System.out.println(collect);

        //对数据进行条件排序的两种方法
        list.sort((p,p1) -> Integer.parseInt(p.getId())-Integer.parseInt(p1.getAge()));

        list.sort( Comparator.comparing(person::getId) );

        list.forEach(System.out::print);
    }
}
